import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import * as tabBar from '@/utlis/tabbar.js'
const store = new Vuex.Store({
	state: {
		token: '',	
		wx_token: '',
		tabBarList: [],
		path: '',
		page_update_notice: '',
		roleId: '', //0 普通员工，1管理员
		user: {},
		searchData: ''
	},
	getters: {
		page_update_notice: state => state.page_update_notice,
	},
	actions: {
		pageUpdateNotice(context) {
			let val = new Date().getTime();
			context.commit("pageUpdateNotice", val);
		},
		updateSharedData({
			commit
		}, data) {
			commit('setSharedData', data);
		},
	},
	mutations: {
		setSharedData(state, data) {
			state.searchData = data;
		},
		clearSearchData(state) {
		    state.searchData = ''; 
		},
		// 设置用户角色ID
		setRoleId(state, data) {
			state.roleId = data;
			uni.setStorageSync('roleId', data)
			state.tabBarList = tabBar[data];
			uni.setStorageSync('tabBarList', tabBar[data])
		},
		setPath(state, data) {
			state.path = data;
		},
		pageUpdateNotice(state, payload) {
			state.page_update_notice = payload;
		},
	},
})
export default store